import request from '@/utils/request'

// 获取指令类型下拉列表
export function cmdTypeSelect() {
  return request({
    url: `/online/management/cmd/cmd-types/select`,
    method: 'get'
  })
}

// 分页查询指令记录列表
export function cmdPage(params) {
  return request({
    url: `/online/management/cmd`,
    method: 'get',
    params
  })
}

// 分页查询指令执行的终端列表
export function cmd2DevicePage(cmdCode, params) {
  return request({
    url: `/online/management/cmd/${cmdCode}/devices`,
    method: 'get',
    params
  })
}

// 增加一条指令
export function addCmd(data) {
  return request({
    url: `/online/management/cmd`,
    method: 'post',
    data
  })
}

// 删除一条指令
export function deleteCmd(cmdCode) {
  return request({
    url: `/online/management/cmd/${cmdCode}`,
    method: 'delete'
  })
}

// 向指令中 单个SN添加或者txt文件方式批量添加设备
export function addCmdDevices(cmdCode, params) {
  return request({
    url: `/online/management/cmd/${cmdCode}/devices`,
    method: 'post',
    params
  })
}

// 推送指令
export function cmdPush(cmdCode) {
  return request({
    url: `/online/management/cmd/${cmdCode}/push`,
    method: 'post'
  })
}

// 删除指令中的一个终端
export function deleteCmdDevice(cmdCode, devSn) {
  return request({
    url: `/online/management/cmd/${cmdCode}/device/${devSn}`,
    method: 'delete'
  })
}

// 查询指令详情
export function getCmdDetails(cmdCode, devSn) {
  return request({
    url: `/online/management/cmd/${cmdCode}/device/${devSn}`,
    method: 'get'
  })
}

// 查询指令结果（实时结果）
export function syncCmdResult(cmdTypeCode, cmdCode, devSn) {
  return request({
    url: `/online/management/cmd/${cmdTypeCode}/${cmdCode}/device/${devSn}`,
    method: 'get',
    timeout: 60 * 1000
  })
}
// ------------------------------自定义指令-----------------------------------------------------

// 查询所有自定义指令(自定义指令下拉列表)
export function customizeList(id, data) {
  return request({
    url: `/online/management/cmd/customize/select`,
    method: 'get',
    data
  })
}

// 分页查询自定义指令
export function customizePage(params) {
  return request({
    url: `/online/management/cmd/customize`,
    method: 'get',
    params
  })
}

// 根据主键查询自定义指令
export function getCustomize(id) {
  return request({
    url: `/online/management/cmd/customize/${id}`,
    method: 'get'
  })
}

// 新增一条自定义指令
export function addCustomize(data) {
  return request({
    url: `/online/management/cmd/customize`,
    method: 'post',
    data
  })
}

// 编辑更新自定义指令
export function updateCustomize(id, data) {
  return request({
    url: `/online/management/cmd/customize/${id}`,
    method: 'post',
    data
  })
}

// 删除一条自定义指令
export function deleteCustomize(id) {
  return request({
    url: `/online/management/cmd/customize/${id}`,
    method: 'delete'
  })
}

// 查询运营商提取文件默认文件路径
export function getFetchFilePath() {
  return request({
    url: `/online/management/cmd/customize/fetch-file-path`,
    method: 'GET'
  })
}

export function newestCmdPush(devSn) {
  return request({
    url: `/online/management/cmd/${devSn}/latest-cmd-push`,
    method: 'GET'
  })
}
